import 'package:get/get.dart';

import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import '../../../utils/xin_he_toast.dart';
import '../model/xin_he_adopt_tree_record_model_entity.dart';
import 'xin_he_adopt_records_state.dart';

class XinHeAdoptRecordsLogic extends GetxController {
  final XinHeAdoptRecordsState state = XinHeAdoptRecordsState();

  RxList recordsList = [].obs;


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();


    requestMemberAdoptRecords();

  }

  getTitle(String status) {
    String title = '';
    if(status == 'PAY') {
      title = '已完成';
    }else if(status == 'UN_PAY'){
      title = '待支付';

    }else if(status == 'CANCEL'){
      title = '已取消';
    }
    return title;
  }


  requestMemberAdoptRecords() async {
    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId':userId,
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/adoptedTreeOrder/queryAdoptedTreeOrder',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    List dataList = result.data['data'];
    List items = [];
    if(dataList.isNotEmpty){
      for(var e in dataList){
        XinHeAdoptTreeRecordModelEntity model = XinHeAdoptTreeRecordModelEntity.fromJson(e);
        items.add(model);
      }
      recordsList.value = items;

    }

  }


}
